﻿using Blog.Application.Contract.Blogs;
using Blog.Application.Contract.Blogs.Dto;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Pomelo.EntityFrameworkCore.MySql.Query.Internal;

namespace Blog.HttpApi.Host.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class BlogController : ControllerBase
    {
        private readonly IBlogServer _blogServer;

        public BlogController(IBlogServer blogServer)
        {
            _blogServer = blogServer;
        }

        /// <summary>
        /// 创建博客文章
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task CreateBlogAsync(CreateBlogsDto input)
        {
            await _blogServer.CreateBlogAsync(input);
        }

        /// <summary>
        /// 编辑博客
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task UpdateAsync(CreateBlogsDto input)
        {
            await _blogServer.UpdateAsync(input);
        }


        /// <summary>
        /// 删除博客
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task DeleteAsync(Guid id)
        {
            await _blogServer.DeleteAsync(id);
        }

        /// <summary>
        /// 查询博客文章
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<BlogDto> GetAsync(Guid id)
        {
            return await _blogServer.GetAsync(id);
        }
    }
}
